<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : "{{ urlfor "StocksController.Records"}}"
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
            var queryParams = checkQueryTableData(aoData);
            var form = $('.query-form').serializeArray();
            $.each(form, function(i, value){
                queryParams[value.name] = value.value;
            });
			$.post(sSource, JSON.stringify(queryParams),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
			{"data" : "Number", "bSortable": false}
			,{"data" : "OperatorName", "bSortable": false}
            ,{"data" : "OperatorTime", "bSortable": false,render:function(data, type, full, meta) {
                   return timetransDate(data);
             }}
            ,{"data" : "Typeid", "bSortable": false,render:function(data, type, full, meta) {
                    return productTypeidName(data);
             }}
			,{"data" : "Auditing", "bSortable": false,render:function(data, type, full, meta) {
				if(data == 0) {
					return '<span class="am-badge am-badge-warning">盘点中</span>';
				}else if(data == 1) {
					return '<span class="am-badge am-badge-success">盘点完成</span>';
				}
			}}
			 ,{
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"15%",
				"render": function ( data, type, full, meta ) { 
					btns = '';
					if(full.Auditing == 0) { //盘点中
						btns += '<a href="{{ urlfor "StocksController.SaveList" }}/'+ full.Id +'" class="am-icon-edit"> 继续盘点</a>';
					} else {
                        btns += '<a  href="{{ urlfor "StocksController.SaveList" }}/'+ full.Id +'" class="am-icon-edit">商品信息</a>';
                        btns += '<br /><a  href="{{ urlfor "StocksController.ProfitLoss" }}/'+ full.Id +'" class="am-icon-edit am-text-danger">损益表</a>';
                    }
					if(full.Auditing == 0) { //盘点完成
						btns += '<br /><a href="javascript:;"  onclick="delStock('+ full.Id +');return false;" class="am-icon-edit am-text-danger">删除</a>';
					}
					return btns;  
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	
	$("#query-submit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});
	
	function delStock(id) {
		layer.confirm('确定要操作所选记录吗？', function(index){
			$.post('{{ urlfor "StocksController.Delete"}}', {id:id}, function(res){
				if(res.code == 1) {
					layer.msg(res.msg)
				} else {
					tables.ajax.reload();
				}
				layer.close(index);
			}, 'json');
		});
	}
	
	function dialogReback() {
		tables.ajax.reload();
	}
</script>